<template>
  <div class="card-container">
    <el-row :gutter="20">
        <el-col :span="12" :md="8" :lg="6" class="cc" v-for="o in appData" :key="o.id">
          <el-card :body-style="{ padding: '0px'}" shadow="hover" class="card">
            <el-button type="text" class="text-btn" @click="handleAppInfo(o.id)">
              <div class="card-img">
                <img :src="o.icon" class="image">
                <div></div>
              </div>
            </el-button>
            <div class="card-info">
              <el-button type="text" class="text-btn" @click="handleAppInfo(o.id)">
                <div class="title">{{o.name}}</div>
              </el-button>
              <div class="category">{{o.keywords}}</div>
              <div class="description">
                {{o.description}}
              </div>
            </div>
            <kt-button icon="fa fa-wrench" :label="$t('action.install')" :perms="permsInstall" type="success" size="mini" 
            :loading="editLoading" @click="install(o.id)" />
          </el-card>
        </el-col>
    </el-row>
  </div>
</template>

<script>
import KtButton from "@/views/Core/KtButton"
export default {
  name: "KtCard",
  components:{
			KtButton
  },
  props: {
    permsInstall: String,  // 编辑权限标识
    appData: Array // 应用列表数据
	},
  data() {
    return {
      checkAll: false,
      editLoading: false,
      isIndeterminate: true,
      checkedApps: [1, 3, 4],
      allApps: [1,2,3,4,5,6,7,8,9]
    };
  },
  methods: {
    // 安装
		install: function (appId) {
      const params = {chartId: appId}
      this.$api.apps.appInstall(params).then((res) => {
				console.log(res);
				this.editLoading = false
				if(res.code == 200) {
          this.$message({message: '应用安装完成', type: 'success'})
				} else {
					this.$message({message: '应用安装失败, ' + res.msg, type: 'error'})
				}
			})
      console.log("install app: " + appId)
    },
    handleAppInfo(appId) {
      this.$emit('handleAppInfo', appId)
    }
  }
};
</script>

<style scoped lang="scss">
.card-img {
  position: relative;
  height: 110px;
  line-height: 110px;
}
.card-img img {
  max-width: 100%;
  max-height: 100px;
  vertical-align: middle;
}
.card-img>div {
  background: #000;
  opacity: 0;
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
}
.card-img>div:hover {
  opacity: 0.1;
}
.card-info {
  padding-top: 10px;
  margin: 10px 15px;
  border-top: 2px solid #e8e8e8;
}
.card-info .el-button {
  text-align: left;
}
.card-info+.el-button {
  border-radius: unset;
}
.title {
  color: #333;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding: 5px 0;
  font-size: 16px;
}
.title:hover {
  color: #00afca;
}
.category {
  font-size: 0.6rem;
  color: #BBB;
  margin-top: 3px;
  margin-bottom: 10px;
  height: 14px;
}
.description {
  height: 65px;
  line-height: 17px;
  font-size: 0.6rem;
  color: #444;
  word-wrap: break-word;
  overflow: hidden;
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  margin-bottom: 15px;
}
.card-container {
  clear: both;
  padding: 10px;
}
.card {
  margin-bottom: 30px;
  text-align: left;
  background: #fafafa;
}
.text-btn {
  padding: 0;
  border: none;
}
.el-card__body .el-button {
  width: 100%;
}
@media only screen and (min-width: 1600px) {
  .cc {
      width: 16.66667%;
  }
}
@media only screen and (min-width: 2200px) {
  .cc {
      width: 12.5%;
  }
}
</style>
